var MultiSelect	= function(pId,hdId,multiData,allData){
	this.pId	= pId;
	this.hdId	= hdId;
	this.multi	= multiData;
	this.all	= allData;
}
MultiSelect.prototype={
    getSubCategory:function(ev){
        $(ev.target).nextAll('select').remove();
	    var id	= $(ev.target).val();
	    var cls	= ev.data.cls;
	    if(id==0)
	    {
	    	var o	= $(ev.target).prev();
	    	if(o.is('select'))
	    	{
	    		$('#'+cls.hdId).val(o.val());
	    	}
	    	else
	    	{
	    		$('#'+cls.hdId).val(0+"");
	    	}
	    	return;
	    }
	    
	    $('#'+cls.hdId).val(id);
	    var d	= cls.multi['multi_'+id];
	    
	    if(d && d.length>0)
	    {
			var select	= $("<select></select>");
			select.bind("change", {cls: cls}, cls.getSubCategory)
			//select.change(this.getSubCategory);
			select.append($("<option value='0'>请选择</option>"));
			for(var i in d)
			{
				var option=$("<option value='"+d[i].value+"'>"+d[i].name+"</option>");
				select.append(option);
			} 
			select.val(0);
			$(ev.target).after(select);
	    }
    },
    init:function(){
    	var select	= $("<select></select>");
		select.bind("change", {cls: this}, this.getSubCategory)
		//select.change(this.getSubCategory);
		select.append($("<option value='0'>请选择</option>"));
		var d	= this.multi['multi_0'];
	    if(d && d.length>0)
	    {
			for(var i in d)
			{
				var option=$("<option value='"+d[i].value+"'>"+d[i].name+"</option>");
				select.append(option);
			} 
	    }
	    $('#'+this.pId).empty();
	    $('#'+this.pId).append(select);
	    this.firstChild	= select;
    },
    select:function(val){
    	var key		= val;
    	var keys	= new Array();
    	while(this.all[key]){
    		keys.unshift(key);
    		var key	= this.all[key].pid;
    	}
    	var len		= keys.length;
    	this.firstChild.val(keys[0]);
    	var select	= this.firstChild;
    	//if(len>1)
    		select.change();
    //	else
    //		$('#'+this.hdId).val(keys[0]);
    	
    	for(var i=1;i<len;i++){
    		select	= select.next();
    		if(select.is('select')){
    			select.val(keys[i]);
    		//	if(i<len-1)
    				select.change();
    		//	else
    		//		$('#'+this.hdId).val(keys[i]);
    		}else{
    			break;
    		}
    	}
    }
}